// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Rotating Spike Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 56 : TYPE_ROTATINGSPIKE

// Function declarations
reserve function RotatingSpike_DebugDraw
reserve function RotatingSpike_DebugSpawn

// Static Values
public value RotatingSpike_value35 = 0;

// Tables

function RotatingSpike_DebugDraw
	temp7 = object[0].value17
	temp7 -= RotatingSpike_value35
	temp6 = object.direction
	temp6 <<= 8
	DrawSprite(0)
	temp0 = 0
	temp1 = 16
	while temp0 < temp7
		Cos(temp2, temp6)
		temp2 *= temp1
		temp2 <<= 7
		temp2 += object.xpos
		Sin(temp3, temp6)
		temp3 *= temp1
		temp3 <<= 7
		temp3 += object.ypos
		DrawSpriteXY(1, temp2, temp3)
		temp0++
		temp1 += 16
	loop
	Cos(temp2, temp6)
	temp2 *= temp1
	temp2 <<= 7
	temp2 += object.xpos
	Sin(temp3, temp6)
	temp3 *= temp1
	temp3 <<= 7
	temp3 += object.ypos
	DrawSpriteXY(2, temp2, temp3)
end function


function RotatingSpike_DebugSpawn
	CreateTempObject(TypeName[Rotating Spike], 0, object.xpos, object.ypos)
	object[tempObjectPos].value0 = object.direction
	object[tempObjectPos].value0 <<= 16
	if object.direction == FLIP_NONE
		object[tempObjectPos].value1 = 256
	else
		object[tempObjectPos].value1 = -256
	end if
	object[tempObjectPos].value2 = object[0].value17
	object[tempObjectPos].value2 -= RotatingSpike_value35
	object[tempObjectPos].value2++
	object[tempObjectPos].value3 = object[tempObjectPos].value2
	object[tempObjectPos].value3 <<= 4
end function


event ObjectMain
	object.value0 += object.value1
	object.value0 &= 0x1FFFF
	temp0 = object.value0
	temp0 >>= 8
	Cos(object.value4, temp0)
	object.value4 *= object.value3
	object.value4 <<= 7
	object.value4 += object.xpos
	Sin(object.value5, temp0)
	object.value5 *= object.value3
	object.value5 <<= 7
	object.value5 += object.ypos
	temp0 = object.xpos
	temp1 = object.ypos
	object.xpos = object.value4
	object.ypos = object.value5
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_TOUCH, object.entityPos, -8, -8, 8, 8, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		if checkResult == 1
			CallFunction(PlayerObject_Hit)
		end if
	next
	object.xpos = temp0
	object.ypos = temp1
end event


event ObjectDraw
	DrawSprite(0)
	temp0 = 0
	temp1 = 16
	temp4 = object.value0
	temp4 >>= 8
	while temp0 < object.value2
		Cos(temp2, temp4)
		temp2 *= temp1
		temp2 <<= 7
		temp2 += object.xpos
		Sin(temp3, temp4)
		temp3 *= temp1
		temp3 <<= 7
		temp3 += object.ypos
		DrawSpriteXY(1, temp2, temp3)
		temp0++
		temp1 += 16
	loop
	temp1 -= 8
	DrawSpriteXY(2, object.value4, object.value5)
end event


event ObjectStartup
	LoadSpriteSheet("LZ/Objects.gif")
	SpriteFrame(-8, -8, 16, 16, 84, 173)
	SpriteFrame(-8, -8, 16, 16, 101, 173)
	SpriteFrame(-16, -16, 32, 32, 84, 190)
	foreach (TypeName[Rotating Spike], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].value0 = object[arrayPos0].direction
		object[arrayPos0].value0 <<= 15
		object[arrayPos0].direction = FLIP_NONE
		object[arrayPos0].value1 = object[arrayPos0].propertyValue
		object[arrayPos0].value1 &= 240
		if object[arrayPos0].value1 >= 128
			object[arrayPos0].value1 -= 256
		end if
		object[arrayPos0].value1 <<= 4
		object[arrayPos0].value2 = object[arrayPos0].propertyValue
		object[arrayPos0].value2 &= 15
		object[arrayPos0].value3 = object[arrayPos0].value2
		object[arrayPos0].value3 <<= 4
	next
	temp0 = 0
	RotatingSpike_value35 = DebugMode_ObjCount
	RotatingSpike_value35--
	while temp0 < 4
		SetTableValue(TypeName[Rotating Spike], DebugMode_ObjCount, DebugMode_TypesTable)
		SetTableValue(RotatingSpike_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
		SetTableValue(RotatingSpike_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
		DebugMode_ObjCount++
		temp0++
	loop
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
